package com.chen.shopping_manager_api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.shopping_common.pojo.Brand;
import com.chen.shopping_common.result.BaseResult;
import com.chen.shopping_common.result.BusException;
import com.chen.shopping_common.service.BrandService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/brand")
public class BrandController {
    @DubboReference
    private BrandService brandService;

    @GetMapping("/findById")
    public BaseResult<Brand> findBrandById(Long id){
        return BaseResult.ok(brandService.findById(id));
    }

    @GetMapping("/all")
    public BaseResult findAllBrand(){
        return BaseResult.ok(brandService.findAllBrand());
    }

    @PostMapping("/add")
    public BaseResult addBrand(@RequestBody Brand brand){
        brandService.addBrand(brand);
        return BaseResult.ok();
    }

    @PutMapping("/update")
    public BaseResult updateBrand(@RequestBody Brand brand){
        brandService.updateBrand(brand);
        return BaseResult.ok();
    }

    @DeleteMapping("/delete")
    public BaseResult deleteBrand(Long id){
        brandService.deleteBrand(id);
        return BaseResult.ok();
    }

    //分页查询返回结果要加泛型
    @GetMapping("/search")
    public BaseResult<Page<Brand>> findBrandByPage(Brand brand, int page , int size){
        return BaseResult.ok(brandService.findBrandByPage(brand,page,size));
    }
}
